#!/bin/bash
# Script jetty - jboos - tomcat - vhosts - opt/*
# saida:  "HOSNAME APP"
# Autor: Sandrade
# Data: 09-01-2012
# usar: ssh sandrade@server 'bash -s' < script.sh >> out

JBOSS_DIR="/opt/UOLI/jboss"
JETTY_DIR="/opt/UOLI/webapps"
TOMCAT_DIR="/opt/UOLI/tomcat"
EXTRA_DIR="/opt/UOLI"
HOSTNAME=`cat /proc/sys/kernel/hostname`
SEDJB=`ps aux |sed -n 's/.*\/\(.\+\)\.jar$/\1/p'`
SEDJT=`ps aux |sed -n 's/.*\/\(.\+\)\.xml$/\1/p'`
APP="UOLzim|UOLbacula|UOL007|UOLmonitor|UOLI|quebec|lost*|javazoneinfo|fpupdater.jar|mon|atualiza-java.sh|UOLlinallator"
APACHESSL=`/opt/apache-ssl/bin/apachectl -S 2>&1 |grep port|awk {'print $4'} |sort|uniq`
APACHEADM=`/opt/apache-adm/bin/apachectl -S 2>&1 |grep port|awk {'print $4'} |sort|uniq`
APACHE=`/opt/apache/bin/apachectl -S 2>&1 |grep port|awk {'print $4'} |sort|uniq`

#HOSTNAME=`hostname -s`

#JBOSS 
ls "${JBOSS_DIR}/" >/dev/null 2>&1
        if [[ "${?}" != "0" ]]; then
                for i in $SEDJB; do
                        echo "$HOSTNAME" $i "Sistema" 
                done
            else
                   for j in "$JBOSS_DIR/"*; do
                        echo "$HOSTNAME" ${j##*/} "Sistema"
                   done
fi
#JETTY
ls "${JETTY_DIR}/" >/dev/null 2>&1
        if [[ "${?}" != "0" ]]; then
                for i in $SEDJT; do
                        echo "$HOSTNAME" $i "Sistema"
                done
            else
                   for j in "$JETTY_DIR/"*; do
                        echo "$HOSTNAME" ${j##*/} "Sistema"
                   done
fi
#TOMCAT
ls "${TOMCAT_DIR}/" >/dev/null 2>&1
        if [[ "${?}" != "0" ]]; then
                for j in "$EXTRA_DIR/"*; do
                        echo "$HOSTNAME" ${j##*/} "Sistema"
                   done
            else
			  for j in "$TOMCAT_DIR/"*; do
				echo "$HOSTNAME" ${j##*/} "Sistema"
			  done
				    for e in `ls $EXTRA_DIR |egrep -v "webapps|jboss|tomcat"`; do
					echo "$HOSTNAME" ${e##*/} "Sistema"
				    done

		  
fi
#/opt
		for op in `ls /opt |egrep -v $APP`; do
			echo "$HOSTNAME" $op "Sistema"
		done

#vhosts
	if [ -e /opt/apache-ssl ]; then
                for i in $APACHESSL; do
                        echo "$HOSTNAME" $i "vhosts"
                done
	fi
	
	if [ -e /opt/apache-adm ]; then
		 for i in $APACHEADM; do
		        echo "$HOSTNAME" $i "vhosts"
		done
	fi
	if [ -e /opt/apache ]; then
	         for i in $APACHE; do
	                echo "$HOSTNAME" $i "vhosts"
	        done
	fi
